<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GX College Social Networking</title>
</head>

<body>
<table width="753" height="366" border="0">
  <tr>
    <td bgcolor="#6699FF" height="34" colspan="6"><marquee>GX College Networking</marquee></td>
  </tr>
  <tr>
    <td bgcolor="#6699FF" width="139" height="43"><a href="/ProfessorHomePage.php">Homepage</a></td>
    <td bgcolor="#6699FF" width="133"><a href="/ProfessorHomePageProfile.php">Profile</a></td>
    <td bgcolor="#6699FF" width="108">Albums</td>
    <td bgcolor="#6699FF" width="170"><a href="/ProfessorHomePageFriend.php">Friends</a></td>
    <td bgcolor="#6699FF" width="115"><a href="/ProfessorHomePageMessage.php">Messages</a></td>
    <td bgcolor="#6699FF" width="62"><a href="/logout.php">Logout</a></td>
  </tr>
  <tr>
    <td bgcolor="#6699FF" height="281">&nbsp;</td>
    <td colspan="5">
   <?php 
session_start(); 
$username = $_SESSION['username'];
$cuid = $_POST['cuidrec'];
//echo 'Message'.$cuid;

$conn = oci_connect("gaurav", "gaurav", "xe"); 

 $query =    "SELECT * FROM   Candidate C WHERE C.Cuid = :cuid";
	 
	// $query = "SELECT * FROM   Candidate C WHERE  C.Cuid = :cuid";

  $conn = oci_connect("gaurav", "gaurav", "xe"); 
  $bindargs = array();
  array_push($bindargs, array('CUID', $cuid, -1));

     $pointer = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW,$bindargs);
 //  $pointer = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW); 


  ui_print_modify_candidate($pointer[0], $_SERVER['SCRIPT_NAME']);
  
  // Execute query and display results 
/*function db_do_query($conn, $statement)
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }

  $r = oci_execute($stid, OCI_DEFAULT);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
 $r = oci_fetch_all($stid, $results, null, null,
                     OCI_FETCHSTATEMENT_BY_ROW);
  return($results);
}*/

function db_do_query($conn, $statement, $resulttype, $bindvars = array())
{
$stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }

  // Bind the PHP values to query bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value
    $$b[0] = $b[1];  
    // oci_bind_by_name(resource, bv_name, php_variable, length)
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]); 
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }
  $r = oci_execute($stid, OCI_DEFAULT);
  if (!$r) {
        db_error($stid, __FILE__, __LINE__);
  }
  $r = oci_fetch_all($stid, $results, null, null, $resulttype);
  return($results);
}

function db_error($r = false, $file, $line)
{
  $err =  $r ? oci_error($r) : oci_error();

  if (isset($err['message'])) {
    $m = htmlentities($err['message']);
  }
  else {  
    $m = 'Unknown DB error';
  }

  echo '<p><b>Error</b>: at line '.$line.' of '.$file.'</p>';
  echo '<pre>'.$m.'</pre>';

  exit;
}

function ui_print_modify_candidate($empdetails, $posturl)
{
  if (!$empdetails) {
    echo '<p>No Candidate record selected</p>';
  }
  else {
    $cuid = htmlentities($empdetails['CUID']);
    $firstname = htmlentities($empdetails['FNAME']);
    $middlename = htmlentities($empdetails['MNAME']);
    $lastname = htmlentities($empdetails['LNAME']);
    $address1 = htmlentities($empdetails['ADDRESS1']);
    $address2 = htmlentities($empdetails['ADDRESS2']);
	$city = htmlentities($empdetails['CITY']);
    $state = htmlentities($empdetails['STATE']);
    $country = htmlentities($empdetails['COUNTRY']);
    $zipcode = htmlentities($empdetails['ZIPCODE']);
    $cellnumber = htmlentities($empdetails['CELLNUMBER']);
    $sex = htmlentities($empdetails['SEX']);

    echo <<<END
  <form method="post" action="$posturl">
  <table size="1000">
    <tr>
      <td bgcolor="#0099FF">Candidate ID</td>
      <td><input type="text" readonly name="cuid" value="$cuid" size="15"></td></tr>
    <tr>
      <td bgcolor="#0099FF">First Name</td>
      <td>
	  <input type="text" readonly name="firstname" value="$firstname" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#0099FF">Middle Name</td>
      <td><input type="text" readonly name="middlename" value="$middlename" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#0099FF">Last Name</td>
      <td><input type="text" readonly name="lastname" value="$lastname" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#0099FF">Address 1</td>
      <td><input type="text" readonly name="address1" value="$address1" size="40"></td>
    </tr>
	 <tr>
      <td bgcolor="#0099FF">Address 2</td>
      <td><input type="text" readonly name="address2" value="$address2" size="40"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">City</td>
      <td><input type="text" readonly name="city" value="$city" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">State</td>
      <td><input type="text" readonly name="state" value="$state" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">Country</td>
      <td><input type="text" readonly name="country" value="$country" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">ZipCode</td>
      <td><input type="text" readonly name="zipcode" value="$zipcode" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">Cell Number</td>
      <td><input type="text" readonly name="cellnumber" value="$cellnumber" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#0099FF">Sex</td>
      <td><input type="text" readonly name="sex" value="$sex" size="15"></td>
    </tr>
  </table>
  
  </form>
END;
}
  }
  
  $count=0;
  $count1=0;
  $count2=0;
  
$stmtt = oci_parse($conn, "SELECT Accepted FROM Connects C WHERE (C.Friend1 = '$username' and C.Friend2 = '$cuid') or (C.Friend1 = '$cuid' and C.Friend2 = '$username')"); 

$stmt1 = oci_parse($conn, "SELECT Accepted FROM Connects C WHERE (C.Friend1 = '$username' and C.Friend2 = '$cuid') or (C.Friend1 = '$cuid' and C.Friend2 = '$username') and C.Accepted like 'No'"); 

$stmt2 = oci_parse($conn, "SELECT Accepted FROM Connects C WHERE (C.Friend1 = '$username' and C.Friend2 = '$cuid') or (C.Friend1 = '$cuid' and C.Friend2 = '$username') and C.Accepted like 'Yes'"); 
 
oci_execute($stmtt, OCI_DEFAULT); 
oci_execute($stmt1, OCI_DEFAULT); 
oci_execute($stmt2, OCI_DEFAULT); 

while ($res = oci_fetch_row($stmtt)) 
{ 
$count++;
//echo "Username: ".$username. "Password: ".$password;
//echo 'msg'.$res[0];
}

/*while ($res = oci_fetch_row($stmt1)) 
{ 
//$count1++;
//echo "Username: ".$username. "Password: ".$password;
echo 'msg'.$res[0];
}

while ($res = oci_fetch_row($stmt2)) 
{ 
$count2++;
//echo "Username: ".$username. "Password: ".$password;
//echo 'msg'.$res[0];
}*/
  
/*$count=0;
  $count1=0;
  $count2=0;

$stmt = "SELECT * FROM Connects C WHERE (C.Friend1 = :username and C.Friend2 = :cuid) or (C.Friend1 = :cuid and C.Friend2 = :username)";

$stmt1 = "SELECT * FROM Connects C WHERE (C.Friend1 = :username and C.Friend2 = :cuid) or (C.Friend1 = :cuid and C.Friend2 = :username) and C.Accepted like 'No'";

$stmt2 = "SELECT * FROM Connects C WHERE (C.Friend1 = :username and C.Friend2 = :cuid) or (C.Friend1 = :cuid and C.Friend2 = :username) and C.Accepted like 'Yes'";

  $bindargs1 = array();
  array_push($bindargs1, array('CUID', $cuid, -1));
  array_push($bindargs1, array('USERNAME', $username, -1));

  $pointer = db_do_query($conn, $stmt, OCI_FETCHSTATEMENT_BY_ROW,$bindargs1);
  $pointer1 = db_do_query($conn, $stmt1, OCI_FETCHSTATEMENT_BY_ROW,$bindargs1);
  $pointer2 = db_do_query($conn, $stmt2, OCI_FETCHSTATEMENT_BY_ROW,$bindargs1);


if($pointer[0]!=null)
{
$count++;
}

if($pointer1[0]!=null)
{
$count1++;
}

if($pointer2[0]!=null)
{
$count2++;
}*/
if($count==1)
{
while ($res1 = oci_fetch_row($stmt1)) 
{ 
//$count1++;
//echo "Username: ".$username. "Password: ".$password;
//echo 'msg'.$res[0];
if($res1[0]=='No')
{
//echo 'You are already Connected with this Candidate';
?><script language='javascript'>alert('You have already invited this Candidate. Have Patience!');</script><?php
}
}
while ($res2 = oci_fetch_row($stmt2)) 
{ 
//$count2++;
//echo "Username: ".$username. "Password: ".$password;
//echo 'msg'.$res[0];
if($res2[0]=='Yes')
{
//echo 'You are already Connected with this Candidate';
?><script language='javascript'>alert('You are already Connected with this Candidate!');</script><?php
}
}
}
else
{?>
<form method="post" action="/CheckConnectRequestProfessor.php">
<input type="hidden" name="cuid" value="<?php echo $cuid;?>" />
<input type="submit" name="Submit" value="Connect with Candidate!">
</form><?php
}

  ?>

    </td>
  </tr>
</table>
</body>
</html>


